/**
 * ClassName: O1ArrayTest
 * Package: PACKAGE_NAME
 * Description:
 *
 * @Author 糕糕
 * @Create 2024-01-28 17:01
 * @Version 1.0
 */
public class O1ArrayTest {

    public static void main(String[] args) {
        //声明数组 静态初始化 数组变量的赋值与数组元素的赋值操作同时进行
        double[] prices;
        prices = new double[]{1, 2, 3, 4};


//        String[] foods;
//        foods = new String[]{"sdf", "fsd", "fsd"};

        //声明数组 动态初始化 数组变量的赋值与数组元素的赋值操作分开进行
        String[] foods = new String[4];
        foods = new String[]{"小", "俺", "睡", "觉"};

        //其他正确的方式
        //初始默认是 0
        int arr2[] = new int[3];
        for (int i = 0; i < arr2.length; i++) {
            double item = arr2[i];
            System.out.println(item + "arr2");
        }


        int[] arr1 = {1, 2, 3, 4};//类型推断


        //2.数组元素的调用
        //通过角标的方式，获取数组的元素
        //角标的范围从0开始，到数组的长度-1结束
        prices[0] = 2;
        prices[1] = 4;
        prices[2] = 6;
        prices[3] = 8;


        //3.数组的长度
        System.out.println(prices.length);

        //4.如何遍历数组
        for (int i = 0; i < foods.length; i++) {
            String item = foods[i];
            System.out.println(item);
        }

        for (int i = 0; i < prices.length; i++) {
            double item = prices[i];
            System.out.println(item);
        }

    }
}
